(function() {
	var indexUtil =  {
		head : null,
		init : function() {
			var me = this;
			// var fullscreen = require('home:widget/ui/fullscreen/fullscreen.js');
			// me.fullscreen = new fullscreen();
			// var head = require('home:widget/ui/whitehead/whitehead.js');
			// me.head = new head($('#full_screen') , 'white');
			var glide = $('.slider').glide({
				arrows:false,
				autoplay:6000,
				animationDuration:1000
			}).css('visibility','visible');
			me.getData();
//			me.getProfitList();
			me.getTopNotice();
			me.eventCenter();
		},
		getData : function() {
			var me = this;
			$.getJSON('/plat/plat_fund_summary' ,function (data) {
				if(data && data.error_no == 0 && data.data) {
					$('#user_count .ob_title').text(data.user_count);
					$('#today_credit .ob_title').text("￥" + mathUtil.toCredit(data.data.plat_total_buy));
					
					$('#credit_count .ob_title').text(data.data.credit_assemble_total);
					$('#plat_count .ob_title').text(data.data.credit_plat_total);
					var percent = mathUtil.toPercent(data.data.weight_profit_years_percent);
					$('.profit_percent').html(percent+'<span>%</span>');
				} else {
					if(data.error_no != 0) {
						alert(data.error_message);
						
					}
				}
			})
		},
		eventCenter: function() {
			$('#intro_block_2 .more').click(function() {
				if(event.preventDefault) {
					event.preventDefault();
				} else {
					event.returnValue =false;
				}
				window.scroll(0,$('#start_section').position()['top'] - 140);
			})
		},
		getTopNotice:function() {
			$.getJSON('/about/getTopNotice', function(data) {
				if(!data || data.error_no != 0 || data.data.length==0) {
					$('#notice_wrapper').hide();
					return;
				}
				$('#notice_wrapper').show();
				for(var index in data.data) {
					var el = data.data[index];
					$('#m').append('<div><a href="'+ el['url']+ '" target="_blank">' + el['title']+ '</a><span>' + new Date(el['time']* 1000).pattern('yyyy-MM-dd')+ '</span></div>');
				}
			});
		},
		getProfitList : function() {
			var me = this;
			var type="day";
			$.getJSON('/plat/plat_profit_trend',{'type':type},function(data) {
				var date_list = [];
				var flab_list = [];
				var zrb_list = [];
				if(!data || data.error_no != 0) {
					// alert(data.error_message);
					$('#profit_compare').hide();
					return;
				}
				for(var index in data.data.zrb_list) {
					date_list.push(new Date(data.data.zrb_list[index].date * 1000).pattern('MM-dd'));
					zrb_list.push(parseFloat((parseFloat(data.data.zrb_list[index].profit_percent) * 100).toFixed(2)));
					if(data.data.flab_list) {
						flab_list.push(parseFloat((parseFloat(data.data.flab_list[index].profit_percent)* 100).toFixed(2)));
					}
				}
				$('#profit_compare').highcharts({
		    		credits : {
		    			enabled:false
		    		},
		            title: {
		                text: '年化收益率趋势',
		                x: -20
	        	    },
	        	    xAxis: {
	        	    	type:'datetime',
	                	categories: date_list
	            	},
	            	yAxis: {
	            		min:13,
		                title: {
		                    text: '年化收益率(%)'
		                },
		                plotLines: [{
		                    value: 0,
		                    width: 1,
		                    color: '#808080'
		                }]
		            },
				    tooltip: {
		                valueSuffix: '%'
		            },
		            plotOptions : {
		            	area : {
		            		fillOpacity:0.2
		            	}
		            },
		            series: [{
		            	type : 'area',
		                name: '真融宝',
		                data: zrb_list,
		                color:'#8a8ae6'
	            	}]
				});
			});
		}
	}
	indexUtil.init();
})();


